package com.goods.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.goods.pojo.Book;
import com.goods.pojo.Category;
import com.goods.pojo.Page;

public interface BookMapper {

	// 根据书籍信息（动态SQL）查询所有书籍
	List<Book> find(@Param("cid")String cid,@Param("bname")String bname,@Param("author")String author, @Param("press")String press,@Param("pc")int pc,@Param("ps")int ps);

	// 查询书籍总记录数（动态SQL）
	int Count(@Param("cid")String cid,@Param("bname")String bname,@Param("author")String author, @Param("press")String press); 

	// 查询一本书详细信息
	@Select("select * from t_book where bid = #{0}")
	Book findByBid(String bid);
	
	// 查询分类编号查询分类
	@Select("select * from t_category where cid = #{0}")
	Category findByCid(String cid);

	// 查询指定分类下图书的个数
//	@Select("select count(*) from t_book where cid = #{0}")
//	int findBookCountByCategory(String cid);
	
	// 添加图书
	@Insert("insert into t_book(bid,bname,author,price,currPrice,discount,press,publishtime,edition,pageNum,wordNum,printtime,booksize,paper,cid,image_w,image_b) values(#{bid},#{bname},#{author},#{price},#{currPrice},#{discount},#{press},#{publishtime},#{edition},#{pageNum},#{wordNum},#{printtime},#{booksize},#{paper},#{cid},#{image_w},#{image_b})")
	int add(Book book);

	// 删除图书
	@Delete("delete from t_book where bid = #{0}")
	int delete(String bid);
	
	// 修改图书
	@Update("update t_book set bname=#{bname},author=#{author},price=#{price},currPrice=#{currPrice},discount=#{discount},press=#{press},publishtime=#{publishtime},edition=#{edition},pageNum=#{pageNum},wordNum=#{wordNum},printtime=#{printtime},booksize=#{booksize},paper=#{paper},cid=#{cid} where bid=#{bid}")
	int edit(Book book);
	
}
